package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.FriendshipComment;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.mapper.FriendshipCommentMapper;
import cn.wolfcode.trip.base.service.IFriendshipCommentService;
import cn.wolfcode.trip.base.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FriendshipCommentServiceimpl implements IFriendshipCommentService {

    @Autowired
    private FriendshipCommentMapper commentMapper;

    @Override
    public FriendshipComment saveComment(FriendshipComment comment) {

        comment.setUser(UserContext.getCurrentUser());
        commentMapper.insert(comment);
        return comment;
    }

    @Override
    public int selectTotalCountForUnreadComment() {
        return commentMapper.selectTotalCountForUnreadComment(UserContext.getCurrentUser());
    }


    @Override
    public List<FriendshipComment> selectForComment() {
        Boolean read = false;
        User user = UserContext.getCurrentUser();
        return commentMapper.selectForComment(user.getId(),read);
    }

    @Override
    public void updateRead(Long friendshipCommentId) {
        commentMapper.updateRead(friendshipCommentId);

    }
}
